package com.xxwy.ddu.cms.authonrize.service.impl;

import com.xxwy.ddu.cms.authonrize.entity.Access;
import com.xxwy.ddu.cms.authonrize.entity.MenuButton;
import com.xxwy.ddu.cms.authonrize.entity.MenuMain;
import com.xxwy.ddu.cms.authonrize.mapper.AccessMapper;
import com.xxwy.ddu.cms.authonrize.service.IAccessService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.applet.Main;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xxwy
 * @since 2018-09-05
 */
@Service
public class AccessServiceImpl extends ServiceImpl<AccessMapper, Access> implements IAccessService {

    @Autowired
    AccessMapper accessMapper;

    @Override
    public List<String> getUserUrls(String name) {
        //todo:修改此方法，缓存上
        return accessMapper.getUserUrls(name);
    }

    @Override
    public List<Access> getAllAccessInfo(Integer rId) {
        List<Access> allAccess = accessMapper.getAccessInfo(0);
        if(rId!=null) {
            List<Access> oneAccess = accessMapper.getAccessInfo(rId);
            if (allAccess != null && oneAccess != null) {
                allAccess.forEach(z -> {
                    boolean b = oneAccess.stream().anyMatch(x -> x.getaId().equals(z.getaId()));
                    if (b) {
                        z.setAccess(true);
                    }
                });
            }
        }
        return allAccess;
    }

}
